package com.three.controller;

import com.three.aop.LogAnotation;
import com.three.entity.Staff;
import com.three.mapper.StaffMapper;
import com.three.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author 袁大毛
 * * @date 2024/10/30 下午6:54
 * @描述
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private StaffMapper staffMapper;
    @Autowired
    private HttpSession session;
    @RequestMapping("/login")

    public String login(){
        return "login";
    }
    //修改密码
    @GetMapping("/updatePassWord")
    @LogAnotation("修改密码")//日志
    public R update(String oldPassWord,String newPassWord){
        System.out.println(oldPassWord +" "+ newPassWord);
        Staff staff = (Staff) session.getAttribute("staff");
        String password = staff.getPassword();//老密码
        Integer staffid = staff.getStaffid();
        if (oldPassWord.equals(password)){
            staffMapper.updatePassWord(newPassWord,staffid);
            return R.ok();
        }else{
            return R.error("密码错误");
        }
    }
    //发送验证码
    @GetMapping("/sendValidateCode")
    //@LogAnotation("发送验证码")//日志
    public R sendValidateCode(String phone){
        //System.out.println(phone);
        String cha = staffMapper.selectPhone(phone);
        //System.out.println(cha);
        if(phone.equals(cha)){
            return R.ok();
        }else {
            return R.error("手机号不存在");
        }
    }

    //验证手机号是否存在
    //@GetMapping("identityVerification")
    //public R identityVerification(Integer phone){
    //    String cha = staffMapper.selectPhone(phone);
    //    if(phone.equals(cha)){
    //        return R.ok();
    //    }else {
    //        return R.error("手机号不存在");
    //    }
    //}
}